package thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author liangzai
 * @Description:
 */
public class Demo2 {
    public static int count1 = 0;
    public static AtomicInteger count2 = new AtomicInteger(0);
    public static Object locker = new Object();

    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                synchronized (locker){
                    count1++;
                }
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                synchronized (locker){
                    count1++;
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();

        System.out.println(count1);
        System.out.println(System.currentTimeMillis() - start);
    }
}






